<template>
  <div class="wearables-page">
    <div class="page-header">
      <h1>智能穿戴</h1>
      <p>智慧健康，全天候陪伴</p>
    </div>

    <el-row :gutter="20">
      <el-col :span="6" v-for="wearable in wearables" :key="wearable.id">
        <el-card class="wearable-card" shadow="hover" @click="viewDetail(wearable.id)">
          <div class="product-image-container">
            <img :src="wearable.image" :alt="wearable.name" class="product-image">
            <div class="product-badge" v-if="wearable.isNew">新品</div>
            <div class="product-badge discount" v-if="wearable.discount">热销</div>
          </div>
          <div class="product-info">
            <h3>{{ wearable.name }}</h3>
            <p class="product-desc">{{ wearable.description }}</p>
            <div class="product-price">
              <span class="current-price">¥{{ wearable.price }}</span>
              <span class="original-price" v-if="wearable.originalPrice">¥{{ wearable.originalPrice }}</span>
            </div>
            <div class="product-features">
              <span class="feature-tag" v-for="feature in wearable.features" :key="feature">{{ feature }}</span>
            </div>
            <div class="product-actions">
              <el-button type="primary" size="small" @click="viewDetail(wearable.id)">查看详情</el-button>
              <el-button type="success" size="small" @click="addToCart(wearable)">加入购物车</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useCartStore } from '@/stores/cart'

const router = useRouter()
const cartStore = useCartStore()

const wearables = ref([
  {
    id: 'watch-4-pro',
    name: 'HUAWEI Watch 4 Pro',
    price: '2699',
    originalPrice: '2999',
    description: '旗舰智能手表，健康管理专家',
    image: 'https://via.placeholder.com/300x300/333333/FFFFFF?text=Watch+4+Pro',
    features: ['心电图', '血氧监测', 'eSIM独立通话'],
    isNew: true,
    discount: true
  },
  {
    id: 'watch-gt3',
    name: 'HUAWEI Watch GT 3',
    price: '1288',
    description: '经典智能手表，长续航',
    image: 'https://via.placeholder.com/300x300/666666/FFFFFF?text=Watch+GT+3',
    features: ['两周续航', '100+运动模式', '血氧检测'],
    isNew: false,
    discount: false
  },
  {
    id: 'band-8',
    name: 'HUAWEI Band 8',
    price: '249',
    description: '智能手环，全面健康监测',
    image: 'https://via.placeholder.com/300x300/FF6B6B/FFFFFF?text=Band+8',
    features: ['血氧监测', '心率监测', '9.9mm轻薄'],
    isNew: true,
    discount: true
  },
  {
    id: 'freebuds-pro3',
    name: 'HUAWEI FreeBuds Pro 3',
    price: '1499',
    originalPrice: '1699',
    description: '旗舰降噪耳机，智慧动态降噪',
    image: 'https://via.placeholder.com/300x300/4ECDC4/FFFFFF?text=FreeBuds+Pro+3',
    features: ['智慧降噪', '高清音质', '31小时续航'],
    isNew: true,
    discount: false
  },
  // 新增四个智能穿戴
  {
    id: 'watch-fit2',
    name: 'HUAWEI Watch Fit 2',
    price: '799',
    originalPrice: '899',
    description: '时尚运动手表，全面健康监测',
    image: 'https://via.placeholder.com/300x300/5AC8FA/FFFFFF?text=Watch+Fit+2',
    features: ['AMOLED屏', '运动指导', '健康监测'],
    isNew: false,
    discount: true
  },
  {
    id: 'freebuds-5i',
    name: 'HUAWEI FreeBuds 5i',
    price: '499',
    description: '入门降噪耳机，高性价比',
    image: 'https://via.placeholder.com/300x300/FF9500/FFFFFF?text=FreeBuds+5i',
    features: ['主动降噪', '长续航', '舒适佩戴'],
    isNew: true,
    discount: false
  },
  {
    id: 'band-7',
    name: 'HUAWEI Band 7',
    price: '199',
    description: '经典手环，基础健康监测',
    image: 'https://via.placeholder.com/300x300/34C759/FFFFFF?text=Band+7',
    features: ['血氧监测', '心率监测', '超长续航'],
    isNew: false,
    discount: true
  },
  {
    id: 'vision-glass',
    name: 'HUAWEI Vision Glass',
    price: '2999',
    description: '智能眼镜，AR体验',
    image: 'https://via.placeholder.com/300x300/5856D6/FFFFFF?text=Vision+Glass',
    features: ['AR显示', '语音交互', '轻量化'],
    isNew: true,
    discount: false
  }
])

const viewDetail = (wearableId) => {
  router.push(`/goods/${wearableId}`)
}

const addToCart = (wearable) => {
  cartStore.addToCart({
    id: wearable.id,
    name: wearable.name,
    price: wearable.price,
    image: wearable.image,
    description: wearable.description
  }, 1)
  ElMessage.success(`已添加 ${wearable.name} 到购物车`)
}
</script>

<style scoped>
.wearables-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.page-header {
  text-align: center;
  margin-bottom: 40px;
  padding: 20px 0;
}

.page-header h1 {
  color: #c7000a;
  font-size: 32px;
  margin-bottom: 10px;
}

.page-header p {
  color: #666;
  font-size: 16px;
}

.wearable-card {
  margin-bottom: 20px;
  transition: all 0.3s;
  cursor: pointer;
}

.wearable-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.product-image-container {
  position: relative;
}

.product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}

.product-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #ff4757;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
}

.product-badge.discount {
  background: #ffa502;
  top: 40px;
}

.product-info {
  padding: 15px;
}

.product-info h3 {
  margin: 0 0 10px;
  color: #333;
  font-size: 18px;
  height: 24px;
  overflow: hidden;
}

.product-desc {
  color: #666;
  margin-bottom: 10px;
  font-size: 14px;
  height: 40px;
  overflow: hidden;
  line-height: 1.4;
}

.product-price {
  margin: 10px 0;
}

.current-price {
  color: #c7000a;
  font-size: 20px;
  font-weight: bold;
}

.original-price {
  color: #999;
  text-decoration: line-through;
  margin-left: 8px;
  font-size: 14px;
}

.product-features {
  margin: 10px 0;
}

.feature-tag {
  display: inline-block;
  background: #e3f2fd;
  color: #1976d2;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 12px;
  margin-right: 5px;
  margin-bottom: 5px;
}

.product-actions {
  display: flex;
  gap: 8px;
  margin-top: 15px;
}

.product-actions .el-button {
  flex: 1;
}
</style>